| Count | U_Growth | U_Trend | S_Growth | S_Trend | TPU_Growth | TPU_Trend | V_Growth | V_Trend | |
|---|---|---|---|---|---|---|---|---|---|
| ALL | 12419 | 1.52 | 1.67 | 1.54 | 0.13 | ||||
| KSM:KUSD | 2913 | 1.25 | 0.54 | 2.39 | 2.3 | ||||
| KAR:KSM | 2078 | 0.46 | 1.33 | 1.86 | 6.92 | ||||
| KAR:KUSD | 1814 | 0.65 | 0.69 | 0.87 | 0 | ||||
| KUSD:LKSM | 1262 | 0.79 | 0.47 | 1.21 | 0.18 | ||||
| KAR:LKSM | 1011 | 0.9 | 0.41 | 1 | 0 | ||||
| KUSD:QTZ | 508 | 1.22 | 0.6 | 0.62 | 0.68 | ||||
| KAR:QTZ | 498 | 1 | 0.17 | 0.92 | 0.06 | ||||
| KUSD:RMRK | 424 | 0.94 | 1.09 | 1 | 4.77 | ||||
| KBTC:KUSD | 339 | 1.31 | 3.29 | 2.27 | 3.27 | ||||
| KSM:RMRK | 319 | 0.88 | 1.02 | 1.26 | 0 | ||||
| KSM:LKSM | 316 | 0.27 | 0.28 | 1.02 | 0.14 | ||||
| KINT:KUSD | 302 | 0.75 | 0.07 | 1.4 | 0.01 | ||||
| BNC:KUSD | 168 | 0.7 | 0.58 | 1.48 | 0.6 | ||||
| KUSD:PHA | 148 | 0.74 | 1.24 | 1.03 | 0.08 | ||||
| TAI:taiKSM | 116 | 0.47 | 0.36 | 1.44 | 0.37 | ||||
| ARIS2:KUSD | 110 | 1.59 | 0.5 | 0.81 | 0 | ||||
| CSM:KUSD | 89 | 0.58 | 0.37 | 0.62 | 0 | ||||
| ARIS:KSM | 4 | NA | NA | NA | NA |
Last updated: 2022-09-21 20:07:15
Date range of data: 2022-09-08T00:00:54.295 to 2022-09-21T23:56:36.423.
Sources:
Swaps:
Loans:
---
title: "Acala / Karura Dashboards"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
social: menu
source_code: embed
params:
network: Karura
window: 14
---
```{css custom1, echo=FALSE}
.dataTables_scrollBody {
max-height: 100% !important;
}
```
```{r global, include=FALSE}
knitr::opts_chunk$set(
message = FALSE,
warning = FALSE,
comment = "#>"
)
library(kableExtra)
library(formattable)
library(lubridate)
library(flexdashboard)
library(DT)
# Helper function to concat
`%+%` <- function(a, b) paste0(a, b)
# remotes::install_github("ropensci/ghql") # if package is not already installed
library(jsonlite)
library(data.table)
library(subscanr)
library(ghql)
x <- GraphqlClient$new()
window <- params$window
endpoint <- params$endpoint
network <- params$network
# queries ####
dailyLoanCollateral <- getLoansDailyCollateral_acala_loan(network, window)
dailyLoanPositions <- getLoansDailyPositions_acala_loan(network, window)
collaterParams <- getLoansCollateralParams_acala_loan(network)
liquidity <- getLiquidity_acala(network, window)
liquidity[, volumeUSD := as.numeric(volumeUSD) / 1e18]
liq <- liquidity[, .(date, pair, type, volumeUSD)]
liq2 <- liq[, .(.N, sum(volumeUSD)), by = .(pair, date, type)]
setnames(liq2, c("date","N","V2"), c("Date","Observations","volumeUSD"))
liq2[type == 'removeLiquidity', volumeUSD := -volumeUSD]
liq <- liq[, .(.N, sum(volumeUSD)), by = .(date, type)]
setnames(liq, c("date","N","V2"), c("Date","Observations","volumeUSD"))
liq[type == 'removeLiquidity', volumeUSD := -volumeUSD]
swaps2 <- getDailyPools_acala_dex(network, window)
swaps <- getSwaps_acala_dex(network, window)
swaps <- merge(swaps, subscanr::tokens, by.x='token0', by.y='Token') %>% setnames("decimals","decimals0")
swaps[, Name := NULL]
swaps <- merge(swaps, subscanr::tokens, by.x='token1', by.y='Token') %>% setnames("decimals","decimals1")
swaps[, Name := NULL]
swaps[, adj0 := as.numeric(substr(as.character(1e20),1, as.numeric(decimals0) + 1))]
swaps[, adj1 := as.numeric(substr(as.character(1e20),1, as.numeric(decimals1) + 1))]
swaps[, token0InAmount := as.numeric(token0InAmount)]
swaps[, token1OutAmount := as.numeric(token1OutAmount)]
swaps[, price0 := as.numeric(price0) / 1e18]
swaps[, price1 := as.numeric(price1) / 1e18]
swaps[, amount0 := token0InAmount / adj0]
swaps[, amount1 := token1OutAmount / adj1]
swaps[, token0 := subscanr::fixToken(token0, network)]
swaps[, token1 := subscanr::fixToken(token1, network)]
swaps[, tradePath := subscanr::fixToken(tradePath, network)]
swaps[, pathLength := length(strsplit(tradePath, ",")[[1]]) - 1, by = id]
swaps[, volume0USD := amount0 * price0]
swaps[, volume1USD := amount1 * price1]
swaps[, volumeUSDFloat := (volume0USD + volume1USD) / 2]
swaps[volume0USD == 0 & volume1USD > 0, volumeUSDFloat := volume1USD]
swaps[volume1USD == 0 & volume0USD > 0, volumeUSDFloat := volume0USD]
mysort <- function(a, b) ifelse(a < b, a %+% ":" %+% b, b %+% ":" %+% a)
getPath <- function(tradePath) {
# tradePath <- swaps[1]$tradePath
tp <- strsplit(tradePath, ",")[[1]]
n <- length(tp) - 1
if (n == 3) {
return(list(mysort(tp[1],tp[2]), mysort(tp[2],tp[3]), mysort(tp[3],tp[4])))
} else if (n == 2) {
return(list(mysort(tp[1],tp[2]), mysort(tp[2],tp[3]), "NA:NA"))
}
list(mysort(tp[1],tp[2]), "NA:NA", "NA:NA")
}
swaps[, c("pair1", "pair2", "pair3") := getPath(tradePath), by = id]
swaps[, fee := volumeUSDFloat * .03]
swaps[, feeAdj := volumeUSDFloat * .03 * pathLength]
setnames(swaps, "address", "accountId")
pairs <- rbind(swaps[, .N, by = pair1] %>% setnames("pair1", "Pair"),
swaps[, .N, by = pair2] %>% setnames("pair2", "Pair"),
swaps[, .N, by = pair3] %>% setnames("pair3", "Pair"))
# pairs <- rbind(swaps[exclude == FALSE, .N, by = pair1] %>% setnames("pair1", "Pair"),
# swaps[exclude == FALSE, .N, by = pair2] %>% setnames("pair2", "Pair"),
# swaps[exclude == FALSE, .N, by = pair3] %>% setnames("pair3", "Pair"))
pairs <- pairs[, sum(N), by = Pair]
# remove pairs with NA in them
pairs <- pairs[-grep("NA", pairs$Pair)]
pairs <- rbind(data.table(Pair = "ALL", V1 = sum(pairs$V1)), pairs)
pairs <- pairs[order(V1, decreasing = TRUE)] %>%
setnames(c("Pair", "Observations"))
tvl <- swaps2[Date == max(Date)]
stable_dex_pool_size <- tvl[grep("USD", tvl$pair), sum(abs(tvlUSD))]
# Calculate measures for each pair
user_status <- list()
trades_status <- list()
tpu_status <- list()
volume_status <- list()
users_list <- list()
trades_list <- list()
per_list <- list()
volume_list <- list()
# remove old params object before calling render with new params list
rm(params)
for (p in pairs$Pair) {
# p <- pairs$Pair[1]
try(rm(u_list, t_list, p_list, v_list), silent = TRUE)
outname <- "~/R_HOME/websites/web_acala/content/swap_" %+% network %+% "_" %+% p %+% ".html"
unlink(outname)
# Create report for each pair
rmarkdown::render("~/R_HOME/karura-reports/Swap_template.Rmd",
output_file = outname,
params = list(pair = p))
# Store the data for the table
user_status[p] <- activeUsersStatus
trades_status[p] <- tradesStatus
tpu_status[p] <- avgTradeStatus
volume_status[p] <- tradeVolumeStatus
users_list[[p]] <- u_list
trades_list[[p]] <- t_list
per_list[[p]] <- p_list
volume_list[[p]] <- v_list
}
d <- list()
for (x in pairs$Pair) {
d[x] <- paste0('', x, '', collapse = '')
}
inline_plot <- data.frame(Count = pairs$Observations,
U_Growth = unlist(user_status),
U_Trend = "",
S_Growth = unlist(trades_status),
S_Trend = "",
TPU_Growth = unlist(tpu_status),
TPU_Trend = "",
V_Growth = unlist(volume_status),
V_Trend = "")
row.names(inline_plot) <- unlist(d)
getSpecColor <- function(x) {
x[is.na(x)] <- 0
ifelse(x < 1, "red", "green")
}
inline_plot$U_Growth <- cell_spec(inline_plot$U_Growth, color = getSpecColor(inline_plot$U_Growth))
inline_plot$S_Growth <- cell_spec(inline_plot$S_Growth, color = getSpecColor(inline_plot$S_Growth))
inline_plot$TPU_Growth <- cell_spec(inline_plot$TPU_Growth, color = getSpecColor(inline_plot$TPU_Growth))
inline_plot$V_Growth <- cell_spec(inline_plot$V_Growth, color = getSpecColor(inline_plot$V_Growth))
p <- inline_plot %>%
kbl(booktabs = TRUE, escape = FALSE, align='rrrrrrrrr') %>%
add_header_above(c(" " = 1, " " = 1, "Active Users" = 2, "Swap Trades" = 2, "Trades Per User" = 2, "Trading Volume" = 2)) %>%
kable_paper(full_width = FALSE) %>%
column_spec(4, image = spec_plot(users_list, same_lim = FALSE)) %>%
column_spec(6, image = spec_plot(trades_list, same_lim = FALSE)) %>%
column_spec(8, image = spec_plot(per_list, same_lim = FALSE)) %>%
column_spec(10, image = spec_plot(volume_list, same_lim = FALSE))
```
### `r network` Swap Performance Summary
```{r plot_acala, result='asis', out.height = 12}
p
```
Last updated: `r Sys.time()`
Date range of data: `r min(swaps$timestamp)` to `r max(swaps$timestamp)`.
Sources:
* [SubQuery Network](https://explorer.subquery.network/)
Swaps:
* [Acala Dex Data](https://explorer.subquery.network/subquery/AcalaNetwork/acala-dex)
* [Karura Dex Data](https://explorer.subquery.network/subquery/AcalaNetwork/acala-dex)
Loans:
* [Acala Loan Data](https://explorer.subquery.network/subquery/AcalaNetwork/acala-loans)
* [Karura Loan Data](https://explorer.subquery.network/subquery/AcalaNetwork/karura-loan)